yjx.controller('productListController', ['$rootScope', '$scope', '$stateParams', '$fetch', 'modalService', '$timeout', function ($rootScope, $scope, $stateParams, $fetch, modalService, $timeout) {
    $rootScope.tabCtrlName = $rootScope.tabCtrlNameArr[1];
    var api = '/productCenter/products';
    $scope.keyword = $stateParams.keyword;
    $scope.tagId = $stateParams.tagId;

    /*排序*/
    $scope.desc = false;
    $scope.orderBy = function (orderBy, isDesc) {
        $scope.orderByStr = orderBy,
            $scope.desc = isDesc;
    }
    $scope.sortObjectType = function (obj) {
        if ($scope.desc) {
            return -obj[$scope.orderByStr]
        } else {
            return obj[$scope.orderByStr]
        }
    }


    var params = {
        limit: 10,
        offset: 1,
    }
    //$scope.paging = {};
    $scope.pageNum =1;
    $scope.hideShows = true;
    //$scope._update = false;

    /*搜索参数*/
    if ($scope.keyword) {
        params['keyword'] = $scope.keyword;
    }
    if ($scope.tagId) {
        params['tagId'] = $scope.tagId;
    }
    /*初始化获取数据*/
    function getProduct() {
        $fetch.fetch(
            api,
            {
                params: params,
                cache:false,
            }
        ).then(function (data) {
                $timeout(function () {
                    $scope.paging = data.page;
                    $scope.productList = data.rows;
                    //更新状态、数据加载控制
                    $scope._updated = 'reupdated';
                    $scope.hideShows = false;
                })
            }).catch(function (e) {
                modalService.mainMsgError(e.msg);
            })
    }

    getProduct();

    /*翻页处理*/
    $scope.list = function() {
            params.offset = $scope.pageNum;
            $fetch.fetch(
                api,
                {
                    params: params,
                    cache:false,
                }
            ).then(function (data) {
                    $timeout(function () {
                        $scope.paging = data.page;
                        //$scope.productList = data.rows;
                        //if($scope.productList)
                        $scope.productList = $scope.productList.concat(data.rows);
                        //更新状态、数据加载控制
                        $scope._updated = 'updated';
                        $scope.hideShows = false;
                    })
                }).catch(function (e) {
                    modalService.mainMsgError(e.msg);
                })
    }


}]);
